/**
 入驻园区
 **/
(function (vc) {
    var DEFAULT_PAGE = 1;
    var DEFAULT_ROW = 10;
    vc.extends({
        data: {
            adminEquipmentInfo: {
                currentPage: '1',
                adminEquipments: [],
                total: 0,
                records: 1,
                moreCondition: false,
                showFlag: false,
                machineId: '',
                conditions: {
                    machineName: '',
                    machineCode: '',
                    communityId: '',
                    releaseUserName: '',
                    state: '',
                    importanceLevel: '',
                    chargeOrgId: '',
                    firstEnableTime: '',
                    typeId: ''
                },
                useStatus: [],
                importanceLevels: []
            }
        },
        _initMethod: function () {
            //与字典表关联
            vc.getDict('equipment_account', "state", function (_data) {
                $that.adminEquipmentInfo.useStatus = _data;
            });
            //与字典表关联
            vc.getDict('equipment_account', "importance_level", function (_data) {
                $that.adminEquipmentInfo.importanceLevels = _data;
            });
            vc.emit('communityMachineTypeTree', 'initCommunityMachineTypeTree',{
                callName:'adminEquipment'
            })
        },
        _initEvent: function () {
            $that._listEquipmentAccounts(DEFAULT_PAGE, DEFAULT_ROW);
            vc.on('adminEquipment', 'switchType', function (_param) {
                $that.adminEquipmentInfo.conditions.typeId = _param.typeId;
                $that.adminEquipmentInfo.conditions.typeName = _param.typeName;
                $that.adminEquipmentInfo.conditions.flag = 1;
                $that.adminEquipmentInfo.conditions.locationObjId = '';
                $that._listEquipmentAccounts(DEFAULT_PAGE, DEFAULT_ROW);
                $that.adminEquipmentInfo.machineIds = [];
            });
            vc.on('adminEquipment', 'selectMachineType', function (_param) {
                $that.adminEquipmentInfo.conditions.communityId = _param.communityId;
                $that.adminEquipmentInfo.conditions.typeId = _param.typeId;
                $that._listEquipmentAccounts($that.adminEquipmentInfo.currentPage, DEFAULT_ROW);
            });
            vc.on('adminEquipment', 'listEquipmentAccounts', function (_param) {
                $that.adminEquipmentInfo.machineIds = [];
                $that.adminEquipmentInfo.conditions.locationObjId = '';
                $that._listEquipmentAccounts($that.adminEquipmentInfo.currentPage, DEFAULT_ROW);
            });
            vc.on('adminEquipment', 'loadData', function (_param) {
                $that.adminEquipmentInfo.machineIds = [];
                $that.adminEquipmentInfo.conditions.locationObjId = '';
                $that._listEquipmentAccounts($that.adminEquipmentInfo.currentPage, DEFAULT_ROW);
            });
            vc.on('pagination', 'page_event', function (_currentPage) {
                $that.adminEquipmentInfo.currentPage = _currentPage;
                $that._listEquipmentAccounts(_currentPage, DEFAULT_ROW);
                $that.adminEquipmentInfo.machineIds = [];
            });
            vc.on('adminEquipment', 'selectAction', function (_id) {
                $that.adminEquipmentInfo.machineIds = [];
                $that.adminEquipmentInfo.conditions.typeId = '';
                $that.adminEquipmentInfo.conditions.locationObjId = _id;
                $that._listEquipmentAccounts($that.adminEquipmentInfo.currentPage, DEFAULT_ROW);
            })
        },
        methods: {
            _listEquipmentAccounts: function (_page, _row) {
                $that.adminEquipmentInfo.conditions.page = _page;
                $that.adminEquipmentInfo.conditions.row = _row;
                let param = {
                    params: $that.adminEquipmentInfo.conditions
                };
                //发送get请求
                vc.http.apiGet('/equipmentAccount.listAdminEquipmentAccount',
                    param,
                    function (json, res) {
                        let _json = JSON.parse(json);
                        $that.adminEquipmentInfo.total = _json.total;
                        $that.adminEquipmentInfo.records = _json.records;
                        $that.adminEquipmentInfo.adminEquipments = _json.data;
                        vc.emit('pagination', 'init', {
                            total: $that.adminEquipmentInfo.records,
                            dataCount: $that.adminEquipmentInfo.total,
                            currentPage: _page
                        });
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _openEquipmentAccountDetail: function (_adminEquipment) {
                vc.jumpToPage('/#/pages/property/adminEquipmentDetail?machineId=' + _adminEquipment.machineId)
            },
            //查询
            _queryEquipmentAccountMethod: function () {
                $that._listEquipmentAccounts(DEFAULT_PAGE, DEFAULT_ROW);
            },
            //重置
            _resetEquipmentAccountMethod: function () {
                $that.adminEquipmentInfo.conditions.machineName = "";
                $that.adminEquipmentInfo.conditions.machineCode = "";
                $that.adminEquipmentInfo.conditions.state = "";
                $that.adminEquipmentInfo.conditions.importanceLevel = "";
                $that._listEquipmentAccounts(DEFAULT_PAGE, DEFAULT_ROW);
            },
            _queryRoomMethod: function () {
                $that._listEquipmentAccounts(DEFAULT_PAGE, DEFAULT_ROW);
            },
            _showFlag: function () {
                if ($that.adminEquipmentInfo.showFlag) {
                    $that.adminEquipmentInfo.showFlag = false;
                } else {
                    $that.adminEquipmentInfo.showFlag = true;
                }
            },
            _moreCondition: function () {
                if ($that.adminEquipmentInfo.moreCondition) {
                    $that.adminEquipmentInfo.moreCondition = false;
                } else {
                    $that.adminEquipmentInfo.moreCondition = true;
                }
            },
        }
    });
})(window.vc);